package com.share.user.api.factory;


import com.share.common.core.domain.R;
import com.share.user.api.RemoteUserInfoService;
import com.share.user.api.domain.UpdateUserLogin;
import com.share.user.api.domain.UserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Map;

/**
 * 日志服务降级处理
 *
 * @author share
 */
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserInfoService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteUserInfoService create(Throwable throwable)
    {
        log.error("日志服务调用失败:{}", throwable.getMessage());
        return new RemoteUserInfoService()
        {

            @Override
            public R<UserInfo> wxLogin(String code) {
                return R.fail("微信登录失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> updateUserLogin(UpdateUserLogin updateUserLogin, String source) {
                return R.fail("更新用户登录失败:" + throwable.getMessage());
            }

            @Override
            public R<UserInfo> getUserInfo(Long userId, String source) {
                return R.fail("根据用户id:"+userId+",获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<Map<String, Object>> getUserCount(){
                return R.fail("失败:" + throwable.getMessage());
            }
        };

    }
}
